package br.cefetpe.tsi.game.base.views;

import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.toRadians;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Point2D;

import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;

public class HexagonView {
	private HexagonShape[] hexagon = null;

	private Point2D.Double center;

	private double side;

	public HexagonView(Point2D.Double center, double side) {
		this.hexagon = new HexagonShape[7];
		this.center = center;
		this.side = side;
		hexagon[0] = new HexagonShape(this.center, this.side);
		hexagon[1] = new HexagonShape(new Point2D.Double(100
				* sin(toRadians(60)) + this.hexagon[0].getCenter().getX(), 100
				* cos(toRadians(60)) + this.hexagon[0].getCenter().getY()),
				this.side);
		hexagon[2] = new HexagonShape(new Point2D.Double(
				100	* sin(toRadians(60)) + this.hexagon[0].getCenter().getX(),
				(100 * cos(toRadians(60)) + this.hexagon[0].getCenter().getY()) - 100),
				this.side);
		hexagon[3] = new HexagonShape(new Point2D.Double(this.center.x, this.center.y - 100), this.side);
		hexagon[4] = new HexagonShape(new Point2D.Double(
				(100 * sin(toRadians(60)) + this.hexagon[0].getCenter().getX()) - (3 * this.getHexagon()[0].getRadius() + 30), 
				(100 * cos(toRadians(60)) + this.hexagon[0].getCenter().getY()) - 100), 
				this.side); 
		hexagon[5] = new HexagonShape(new Point2D.Double(
				(100 * sin(toRadians(60)) + this.hexagon[0].getCenter().getX()) - (3 * this.getHexagon()[0].getRadius() + 30), 
				100 * cos(toRadians(60)) + this.hexagon[0].getCenter().getY()), 
				this.side);  
		hexagon[6] = new HexagonShape(new Point2D.Double(this.hexagon[0]
				.getCenter().getX(), 100 + this.hexagon[0].getCenter().getY()),
				this.side);
	}

	public void draw(Graphics2D g, HexagonShape hexagon) {
		Graphics2D g2d = (Graphics2D) g;
		g2d.setStroke(new BasicStroke(8));
		g2d.draw(hexagon);
	}

	public void drawBorders(Graphics2D g) {
		for (HexagonShape h : this.hexagon) {
			draw(g, h);
		}
	}

	public void rotate(Graphics2D g2d, double angDegrees, HexagonShape hs) {
		g2d.rotate(toRadians(angDegrees), hs.getCenter().getX(), hs.getCenter()
				.getY());
	}

	public void translate(Graphics2D g2d, Point.Double translationPoint) {
		g2d.translate(translationPoint.x, translationPoint.y);
	}

	public void translate(Graphics2D g2d, double lenghtToTranslate,
			double angleInDegrees) {
		double x = lenghtToTranslate * cos(toRadians(angleInDegrees));
		double y = lenghtToTranslate * sin(toRadians(angleInDegrees));
		g2d.translate(x, y);
	}

	public HexagonShape[] getHexagon() {
		return hexagon;
	}

	public void setHexagon(HexagonShape[] hexagon) {
		this.hexagon = hexagon;
	}

}
